// Package sys
// @Link  https://github.com/bufanyun/hotgo
// @Copyright  Copyright (c) 2024 HotGo CLI
// @Author  Ms <133814250@qq.com>
// @License  https://github.com/bufanyun/hotgo/blob/master/LICENSE
// @AutoGenerate Version 2.15.7
package store

import (
	"context"
	"hotgo/api/admin/storeproduct"
	"hotgo/internal/model/input/store"
	"hotgo/internal/service"
)

var (
	StoreProduct = cStoreProduct{}
)

type cStoreProduct struct{}

// List 查看商品列表
func (c *cStoreProduct) List(ctx context.Context, req *storeproduct.ListReq) (res *storeproduct.ListRes, err error) {
	list, totalCount, err := service.SysStoreProduct().List(ctx, &req.StoreProductListInp)
	if err != nil {
		return
	}

	if list == nil {
		list = []*store.StoreProductListModel{}
	}

	res = new(storeproduct.ListRes)
	res.List = list
	res.PageRes.Pack(req, totalCount)
	return
}

// Export 导出商品列表
func (c *cStoreProduct) Export(ctx context.Context, req *storeproduct.ExportReq) (res *storeproduct.ExportRes, err error) {
	err = service.SysStoreProduct().Export(ctx, &req.StoreProductListInp)
	return
}

// Edit 更新商品
func (c *cStoreProduct) Edit(ctx context.Context, req *storeproduct.EditReq) (res *storeproduct.EditRes, err error) {
	err = service.SysStoreProduct().Edit(ctx, &req.StoreProductEditInp)
	return
}

// MaxSort 获取商品最大排序
func (c *cStoreProduct) MaxSort(ctx context.Context, req *storeproduct.MaxSortReq) (res *storeproduct.MaxSortRes, err error) {
	data, err := service.SysStoreProduct().MaxSort(ctx, &req.StoreProductMaxSortInp)
	if err != nil {
		return
	}

	res = new(storeproduct.MaxSortRes)
	res.StoreProductMaxSortModel = data
	return
}

// View 获取指定商品信息
func (c *cStoreProduct) View(ctx context.Context, req *storeproduct.ViewReq) (res *storeproduct.ViewRes, err error) {
	data, err := service.SysStoreProduct().View(ctx, &req.StoreProductViewInp)
	if err != nil {
		return
	}

	res = new(storeproduct.ViewRes)
	res.StoreProductViewModel = data
	return
}

// Delete 删除商品
func (c *cStoreProduct) Delete(ctx context.Context, req *storeproduct.DeleteReq) (res *storeproduct.DeleteRes, err error) {
	err = service.SysStoreProduct().Delete(ctx, &req.StoreProductDeleteInp)
	return
}

// Status 更新商品状态
func (c *cStoreProduct) Status(ctx context.Context, req *storeproduct.StatusReq) (res *storeproduct.StatusRes, err error) {
	err = service.SysStoreProduct().Status(ctx, &req.StoreProductStatusInp)
	return
}

// Switch 更新商品开关状态
func (c *cStoreProduct) Switch(ctx context.Context, req *storeproduct.SwitchReq) (res *storeproduct.SwitchRes, err error) {
	err = service.SysStoreProduct().Switch(ctx, &req.StoreProductSwitchInp)
	return
}
